
<#--包名-->
package ${mapperBean.serviceImplPackagePath};

<#--bean的包路径-->
import ${mapperBean.beanPackagePath}.${mapperBean.beanName?cap_first};
<#--接口包名-->
import ${mapperBean.servicePackagePath}.${mapperBean.serviceClassName?cap_first};
<#--引入mapper-->
import ${mapperBean.mapperPackagePath}.${mapperBean.mapperClassName?cap_first};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.chinaunicom.sdsi.frm.base.BaseService;
import com.github.pagehelper.PageInfo;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class ${mapperBean.serviceImplClassName?cap_first} extends BaseService implements ${mapperBean.serviceClassName?cap_first}{

	<#--注入mapper-->
	@Autowired
	private ${mapperBean.mapperClassName} ${mapperBean.mapperClassName?uncap_first};
	/**
	 * 分页查询
	 */
	@Override
	public JSONObject search4PageList(${mapperBean.beanName} ${mapperBean.beanName?uncap_first},Integer start, Integer length){
		setPageInfo(start,length);
		<#--得到结果集-->
		List<${mapperBean.beanName}> beanList=${mapperBean.mapperClassName?uncap_first}.search4PageList(${mapperBean.beanName?uncap_first});
		PageInfo<${mapperBean.beanName}> page = new PageInfo<${mapperBean.beanName}>(beanList);
		JSONObject obj = null;
		JSONArray array = new JSONArray();
		
		for(${mapperBean.beanName} bl :beanList){
			obj = new JSONObject();
			<#--组装前台需要数据-->
			<#list beanList as column>
				<#--如是台帐显示或是主键-->
				<#if column.isList='1' || column.isKey='1'>
					obj.put("${column.newColumnName}",bl.get${column.newColumnName?cap_first}());
				</#if>
  			</#list>
			array.add(obj);
		}
		obj = new JSONObject();
		obj.element("data", array);
		obj.element("recordsTotal", page.getTotal());
		obj.element("recordsFiltered", page.getTotal());
		obj.element("draw", 0);
		return obj;
	}
	
	/**
	 * 查询单条数据
	 */
	@Override
	public ${mapperBean.beanName} selectByPrimaryKey(${mapperBean.beanName} ${mapperBean.beanName?uncap_first}){
		
		${mapperBean.beanName} bean=${mapperBean.mapperClassName?uncap_first}.selectByPrimaryKey(${mapperBean.beanName?uncap_first});
		return bean;
	}
	
	/**
	 * 删除单条数据
	 */
	@Override
	public int deleteByPrimaryKey(${mapperBean.beanName} ${mapperBean.beanName?uncap_first}){
		int delnum = ${mapperBean.mapperClassName?uncap_first}.deleteByPrimaryKey(${mapperBean.beanName?uncap_first});
		return delnum;
	}

	/**
	 * 保存数据
	 */
	@Override
	public int addObject(${mapperBean.beanName} ${mapperBean.beanName?uncap_first}){
		int insertnum = ${mapperBean.mapperClassName?uncap_first}.addObject(${mapperBean.beanName?uncap_first});
		return insertnum;
	}

	/**
	 * 修改单条数据
	 */
	@Override
	public int updateByPrimaryKey(${mapperBean.beanName} ${mapperBean.beanName?uncap_first}){
		int updatetnum = ${mapperBean.mapperClassName?uncap_first}.updateByPrimaryKey(${mapperBean.beanName?uncap_first});
		return updatetnum;
	}

}